package cn.wolfcode.crm.domain;

import com.alibaba.druid.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Getter
@Setter
@ToString
public class Employee {
    public static final int STATE_NORMAL = 1;//在职

    public static final int STATE_QUIT = 0;//离职

    private Long id;

    private String username;

    private String realname;

    private String password;

    private String tel;

    private String email;

    private Department dept;
    private String img; // 用户图片


    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date hiredate;

    private int state;

    private boolean admin;

    //维护员工与角色多对多的关系
    private List<Role> roles = new ArrayList<>();


    public String getSmallImagePath() {
        if (!StringUtils.isEmpty(img)) {
            String[] split = img.split("\\.");
            return split[0] + "_small." + split[1];
        }
        return null;
    }

}